package com.phonepn.mymall.goods.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * 数据源配置
 *
 * @author quifar
 */
@Configuration
public class DataSourceConfig {

    @Bean
    @RefreshScope // 数据源随配置内容改变而改变
    public DataSource dataSource(DatasourceBean datasourceBean) {
        HikariDataSource ds = new HikariDataSource();
        ds.setDriverClassName(datasourceBean.getDriverClassName());
        ds.setJdbcUrl(datasourceBean.getUrl());
        ds.setUsername(datasourceBean.getUsername());
        ds.setPassword(datasourceBean.getPassword());
//        ds.setInitialSize(this.initialSize.intValue());
//        ds.setMinIdle(this.minIdle.intValue());
//        ds.setMaxActive(this.maxActive.intValue());
//        ds.setMaxWait(this.maxWait.longValue());
//        ds.setTimeBetweenEvictionRunsMillis(this.timeBetweenEvictionRunsMillis.longValue());
//        ds.setMinEvictableIdleTimeMillis(this.minEvictableIdleTimeMillis.longValue());
//        ds.setValidationQuery(this.validationQuery);
//        ds.setTestWhileIdle(this.testWhileIdle.booleanValue());
//        ds.setTestOnBorrow(this.testOnBorrow.booleanValue());
//        ds.setTestOnReturn(this.testOnReturn.booleanValue());
//        ds.setFilters(this.filters);
        return ds;
    }
}


